<template>
  <div class="serve">
    <!-- 头部 -->
    <HeadPersonal></HeadPersonal>

    <!-- enroll -->
    <div class="enroll">
      <!-- enrollPwdOne -->
      <div class="enrollPwdOne">
        <div class="block">
          <div class="enrollPwdOneC">
            <div class="enrollPwdOneCT">
              <img src="../../static/images/enrollPwdOneCT2.png" />
              <p>设置新密码</p>
            </div>
            <input type="text" placeholder="请输入新密码" class="enrollPwdOneCinput" v-model="password" />
            <input
              type="text"
              placeholder="请再次输入密码"
              class="enrollPwdOneCinput"
              v-model="repassword"
            />
            <div @click="submit" class="enrollPwdOneCsub">提交</div>
            <!-- <input type="submit" value="提交" class="enrollPwdOneCsub"/> -->
          </div>
        </div>
      </div>
    </div>

    <!-- 底部 -->
    <HomeHooter></HomeHooter>
  </div>
</template>

<script>
import $ from "jquery";
import "@/assets/css/home.css";
import "@/assets/css/personal.css";
import HeadPersonal from "@/components/headpersonal";
import HomeHooter from "@/components/footer";

export default {
  name: "enroll",
  data() {
    return {
      password: "",
      repassword: ""
    };
  },
  components: {
    HeadPersonal,
    HomeHooter
  },
  methods: {
    submit() {
      console.log(this.$route.query.phone)
      var reg = /^1[3|5|7|8]\d{9}$/g;
      if (this.$route.query.phone === "") {
        this.$message({
          message: "请输入已验证手机号",
          type: "warning"
        });
        return false;
      }
      if (!reg.test(this.$route.query.phone)) {
        this.$message({
          message: "请填写正确的手机号",
          type: "warning"
        });
        return false;
      }
      if (this.$route.query.code === "") {
        this.$message({
          message: "请输入验证码",
          type: "warning"
        });
        return false;
      }
      if (this.password === "") {
        this.$message({
          message: "请输入密码",
          type: "warning"
        });
        return false;
      }
      if (this.repassword === "") {
        this.$message({
          message: "请再次输入密码",
          type: "warning"
        });
        return false;
      }
      if (this.password !== this.repassword) {
        this.$message({
          message: "两次密码不一致",
          type: "warning"
        });
        return false;
      }
      let id = this.$axios;
      const params = new URLSearchParams();
      params.append("phone", this.$route.query.phone);
      params.append("vrifyCode", this.$route.query.code);
      params.append("password", this.password);
      this.$api.member.updatePassword(id, params).then(res => {
        let result = res.data;
        if (result.code === 1) {
          this.$message({
            message: result.msg,
            type: "success"
          });
          this.$router.push({ name: "enroll-enrollPwdFour" });
        } else {
          this.$message({
            message: result.msg,
            type: "warning"
          });
        }
      });
    }
  }
};
</script>

<style scoped>
</style>